package com.app.controller.backstage;


import com.app.model.AdminUserModel;
import com.app.model.CustomerModel;
import com.app.model.ReportMsgModel;
import com.app.model.UserModel;
import com.app.service.*;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.app.vo.ReportMsgVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RestController
@Data
public class ReportMsgBkController {

    @Autowired
    ReportMsgService reportMsgService;

    @Autowired
    AdminUserService adminUserService;
    @Autowired
    JobPublishService jobPublishService;
    @Autowired
    EnterpriseService enterpriseService;

    //查询举报分类
    @GetMapping("/getReportList")
    public Result<Object> insertReport(HttpServletRequest request,
                                       @RequestParam(required = false) String startTime,
                                       @RequestParam(required = false) String endTime,
                                       Integer page,
                                       Integer limit
                                       ){

        String token = request.getHeader("token");
        String userId = TokenUtils.nothingness(token);
        if (userId == null) {
            return Result.error(405, "token不存在");
        }

        AdminUserModel user = adminUserService.getUserById(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        ReportMsgModel model = new ReportMsgModel();
        model.setStartTime(startTime);
        model.setEndTime(endTime);
        model.setPage(page);
        model.setLimit(limit);
        Page<ReportMsgModel> modelPage = reportMsgService.getList(model);
        List<ReportMsgModel> modelList = modelPage.getRecords();
        int count = (int)modelPage.getTotal();
        for (int i = 0; i < modelList.size(); i++) {
            modelList.get(i).setPublishName(jobPublishService.findAllJobById(modelList.get(i).getPid()).getJobTitle());
            modelList.get(i).setComName(enterpriseService.findModelById(modelList.get(i).getEid()).getEnterpriseName());
        }
        ReportMsgVo vo = new ReportMsgVo();
        vo.setList(modelList);
        vo.setCount(count);
        return Result.success(vo);
    }

}